<template>
  <div class="detail-container">
    <Layout>
      <template>
        <div class="main" v-loading="isLoading" ref="mainContainer">
          <BlogDetail :blog="data" v-if="data" />
          <BlogComment v-if="!isLoading" />
        </div>
      </template>
      <template #right>
        <div class="right" v-loading="isLoading">
          <BlogToc v-if="data" :toc="data.toc" />
        </div>
      </template>
    </Layout>
  </div>
</template>

<script>
import Layout from "@/components/Layout";
import BlogDetail from "./components/Detail/BlogDetail.vue";
import BlogToc from "./components/Detail/BlogToc.vue";
import BlogComment from "./components/Detail/BlogComment.vue";

import fetchData from "@/mixins/fetchData.js";
import mainScroll from "@/mixins/mainScroll.js";
import { getBlog } from "@/api";
import {titleControll} from "@/utils";
export default {
  name: "Detail",
  mixins: [fetchData(null),mainScroll('mainContainer')],
  components: {
    Layout,
    BlogDetail,
    BlogToc,
    BlogComment,
  },
  computed: {
    blogId() {
      return this.$route.params.id;
    },
  },
  methods: {
    async fetchData() {
      const resp =  await getBlog(this.blogId);
      resp.title&&titleControll.setRouterTitle(resp.title);
      return resp;
    }
  },
  updated() {
    const hash = location.hash;
    location.hash = "";
    setTimeout(() => {
      location.hash = hash;
    }, 50);
  },
};
</script>

<style scoped lang='less'>
.detail-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  .main {
    height: 100%;
    box-sizing: border-box;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
  }
  .right {
    width: 300px;
    height: 100%;
    box-sizing: border-box;
    position: relative;
  }
}
</style>